#include "../h/iTimer.h"
#include "../h/iThreadMgr.h"
#include "iTimerThread.h"

iTimer* iTimer::new_instance(iSink* sink, uint32_t id, uint32_t interval, uint32_t loop)
{
	iTimer* tmr = new iTimer();
	tmr->m_sink = sink;
	tmr->m_released = false;
	tmr->m_stopped = false;
	tmr->m_launcher = (iMsgThread*)iThreadMgr::spawn_this();
	tmr->m_param.id = id;
	tmr->m_param.interval = interval;
	tmr->m_param.loop = loop;
	tmr->m_param.user_data = NULL;
	((iTimerThread*)iThreadMgr::spawn_timer())->add_timer(tmr);
	return tmr;
}
void iTimer::release()
{
	m_released = true;
	if(m_stopped)
		delete this;
}